<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="采购方总部编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'purchaserHqCode', validatorRules.purchaserHqCode]" placeholder="请输入采购方总部编码"></a-input>
        </a-form-item>
        <a-form-item label="销售订单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'soNo', validatorRules.soNo]" placeholder="请输入销售订单号"></a-input>
        </a-form-item>
        <a-form-item label="供应商编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierCode', validatorRules.supplierCode]" placeholder="请输入供应商编码"></a-input>
        </a-form-item>
        <a-form-item label="采购方公司编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'buyerCode', validatorRules.buyerCode]" placeholder="请输入采购方公司编码"></a-input>
        </a-form-item>
        <a-form-item label="采购方公司省份" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'buyerProvince', validatorRules.buyerProvince]" placeholder="请输入采购方公司省份"></a-input>
        </a-form-item>
        <a-form-item label="销售订单与采购订单的关联方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'soRelType', validatorRules.soRelType]" placeholder="请输入销售订单与采购订单的关联方式"></a-input>
        </a-form-item>
        <a-form-item label="采购订单id或者采购订单行项目id" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'eipPoNo', validatorRules.eipPoNo]" placeholder="请输入采购订单id或者采购订单行项目id"></a-input>
        </a-form-item>
        <a-form-item label="品类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'categoryCode', validatorRules.categoryCode]" placeholder="请输入品类编码"></a-input>
        </a-form-item>
        <a-form-item label="种类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'subclassCode', validatorRules.subclassCode]" placeholder="请输入种类编码"></a-input>
        </a-form-item>
        <a-form-item label="销售订单状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'soStatus', validatorRules.soStatus]" placeholder="请输入销售订单状态"></a-input>
        </a-form-item>
        <a-form-item label="数据来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'dataSource', validatorRules.dataSource]" placeholder="请输入数据来源"></a-input>
        </a-form-item>
        <a-form-item label="来源数据创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择来源数据创建时间" v-decorator="[ 'dataSourceCreateTime', validatorRules.dataSourceCreateTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="删除标志" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'isDeleted', validatorRules.isDeleted]" placeholder="请输入删除标志"></a-input>
        </a-form-item>
        <a-form-item label="状态表示" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ioflag', validatorRules.ioflag]" placeholder="请输入状态表示"></a-input>
        </a-form-item>
        <a-form-item label="错误信息" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'message', validatorRules.message]" placeholder="请输入错误信息"></a-input>
        </a-form-item>
        <a-form-item label="本条数据是新增/更新" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'status', validatorRules.status]" placeholder="请输入本条数据是新增/更新"></a-input>
        </a-form-item>
        <a-form-item label="全局流水号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'transno', validatorRules.transno]" placeholder="请输入全局流水号"></a-input>
        </a-form-item>

      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "ZpgEipXsddModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
          purchaserHqCode:{rules: [{ required: true, message: '请输入采购方总部编码!' }]},
          soNo:{rules: [{ required: true, message: '请输入销售订单号!' }]},
          supplierCode:{rules: [{ required: true, message: '请输入供应商编码!' }]},
          buyerCode:{rules: [{ required: true, message: '请输入采购方公司编码!' }]},
          buyerProvince:{rules: [{ required: true, message: '请输入采购方公司省份!' }]},
          eipPoNo:{rules: [{ required: true, message: '请输入对应的编码' }]},
          categoryCode:{rules: [{ required: true, message: '请输入品类编码!' }]},
          subclassCode:{rules: [{ required: true, message: '请输入种类编码!' }]},
          soStatus:{},
          dataSource:{rules: [{ required: true, message: '请输入数据来源!' }]},
          dataSourceCreateTime:{rules: [{ required: true, message: '请输入来源数据创建时间!' }]},
          isDeleted:{rules: [{ required: true, message: '请输入删除标志!' }]},
        },
        url: {
          add: "/zpgEipXsdd/add",
          edit: "/zpgEipXsdd/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'purchaserHqCode','soNo','supplierCode','buyerCode','buyerProvince','sorelType','eipPoNo','categoryCode','subclassCode','soStatus','dataSource','dataSourceCreateTime','isDeleted','ioflag','message','status','transno'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'puid','purchaserHqCode','soNo','supplierCode','buyerCode','buyerProvince','sorelType','eipPoNo','categoryCode','subclassCode','soStatus','dataSource','dataSourceCreateTime','isDeleted','ioflag','message','status','transno'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>